<?php
/**
 * Users_LoginController
 *
 * @category Users
 * @package  Users_LoginController
 * @version  $Id$
 */
class Users_LoginController extends Lizard_Core_Controller_Action
{
    /**
     * Login
     *
     */
    public function indexAction()
    {
        $this->view->form = $this->getForm('Login');

        if ($this->_request->isPost()) {
            $result = $this->getTable()->login($this->_getAllParams());

            if ($result->isValid()) {

                if ($this->_getParam('rememberMe')) {
                    Zend_Session::rememberMe(60*60*24*14);
                }

                if ($this->isForwarded()) {
                    // redirect to previous page
                    $this->_helper->redirector->gotoRoute();
                }

                $referer = $this->getRequest()->getServer('HTTP_REFERER');
                $goto = $this->_getParam('goto', $referer);

                if (!$goto || strpos($goto, $this->getRequest()->getRequestUri())) {
                    $goto = '/';
                }
                $this->_redirect($goto);
            }
        }
    }

    /**
     * This action destroys all elements stored in the user's session
     * and redirects back to homepage
     */
    public function logoutAction()
    {
        $this->getTable()->logout();
        $this->_redirect('/');
    }

    /**
     * Forget password
     *
     */
    public function forgotAction()
    {
        //TODO
    }

    /**
     * Change password
     *
     */
    public function changePasswordAction()
    {
        //TODO
    }
}